package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.TreeProblem;

/**
 * @author tzp
 * @since 2020/10/13
 */
public class LC897 implements TreeProblem {
    TreeNode head, tail;

    public TreeNode increasingBST(TreeNode root) {
        if (root == null) return null;
        if (root.left != null) increasingBST(root.left);
        if (head == null) {
            head = root;
            tail = root;
        } else {
            tail.right = root;
            tail = tail.right;
        }
        if (root.right != null) increasingBST(root.right);
        root.left = null;
        return head;
    }

    public static void main(String[] args) {
        Integer[] a = {1, 2, 4, 3, 5, 7, 10, 6, null, 8, null, 11, 9, 15, null, null, null, 12, null, null, null, 13, null, null, null, null, 14};
        TreeNode treeNode = TreeNode.arrayToTreeNode(a);
        TreeNode x = new LC897().increasingBST(treeNode);
        System.out.println(x);
    }
}
